package 题目集.贡献法;

import java.util.Arrays;
import java.util.Scanner;
//todo 细品
public class 子串中单个字符的个数 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String line = sc.nextLine();
        int[] left=new int[line.length()];
        int[] right=new int[line.length()];
        int[] pre=new int[128];   //上一次出现的位置
        Arrays.fill(pre,-1);
        for (int i = 0; i < left.length; i++) {
            char c = line.charAt(i);
            left[i]=pre[c];
            pre[c]=i;
        }
        Arrays.fill(right,line.length());
        Arrays.fill(pre,line.length());
        for (int i = right.length -1; i >= 0; i--) {
            char c = line.charAt(i);
            right[i]=pre[c];
            pre[c]=i;
        }
//        right[line.length()-1]=line.length();
        long sum=0;
        for (int i = 0; i < left.length; i++) {
            sum+= (long) (i - left[i]) *(right[i]-i);
        }
        System.out.println(sum);
    }
}
